/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.loja.client.cadHanUs.cadastro.arvore;

import br.com.loja.client.cadHanUs.cadastro.GerenciadorJP;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/**
 *
 * @author Chapolin
 */
public final class CadItensJT extends JTree {

    private GerenciadorJP cadastroJP;
    private DefaultMutableTreeNode root;
    private DefaultTreeModel treeModel;

    public CadItensJT(GerenciadorJP cadastroJP) {
        this.cadastroJP = cadastroJP;
        root = new DefaultMutableTreeNode("Cadastro");
        treeModel = new DefaultTreeModel(getRoot());
        this.setModel(getTreeModel());
    }

    public void addItem(String item, String... nmSubItem) {

        DefaultMutableTreeNode itens = new DefaultMutableTreeNode(item);
        addSubItens(itens, nmSubItem);
        getRoot().add(itens);
    }

    // Helper method to write an enitre suit of cards to the
    // current tree node
    private void addSubItens(DefaultMutableTreeNode pasta, String... nmSubItem) {
        for (int i = 0; i < nmSubItem.length; i++) {
            pasta.add(new DefaultMutableTreeNode(nmSubItem[i]));
        }
    }

    public GerenciadorJP getCadastroJP() {
        return cadastroJP;
    }

    public void setCadastroJP(GerenciadorJP cadastroJP) {
        this.cadastroJP = cadastroJP;
    }

    public DefaultMutableTreeNode getRoot() {
        return root;
    }

    public void setRoot(DefaultMutableTreeNode root) {
        this.root = root;
    }

    public DefaultTreeModel getTreeModel() {
        return treeModel;
    }

    public void setTreeModel(DefaultTreeModel treeModel) {
        this.treeModel = treeModel;
    }

    public void expandeAllItens(JTree jTree) {
        for (int i = 0; i < jTree.getRowCount(); i++) {
            jTree.expandRow(i);
        }
    }
    
    public void collapseAllItens(JTree jTree) {
        for (int i = 0; i < jTree.getRowCount(); i++) {
            jTree.collapseRow(i);
        }
    }
}
